#include <iostream>
#include <string>
using namespace std;
int find_str2(string a,string b,int start_pos)
{

    for(int g = start_pos;g<=a.length()-b.length();g++)
    {
        // 从起点开始和b匹配，匹配成功+1完全匹配则j=b.length
        for(int j=0;((j<b.length())&&(a[g+j] == b[j]));j++)
        {
            char ta,tb;
            ta = a[g+j];
            tb = b[j];
            if (j == b.length()-1)
                return g;
        }
    }
    return -1;
}
int find_str1(string a,string b,int start_pos)
{
    int n = a.length()-b.length();
    if(start_pos>n||start_pos<0)
        return -1;
    int i = start_pos,j = 0;
    while (i<a.length()&&j<b.length())
    {
        if(a[i] == b[j])
        {
            i++;
            j++;
        }
        else
        {
            i = i-j+1;
            j=0;
        }
    }
    if(j>=b.length())
        return i-j;
    else
        return -1;
}
// 从起点往后匹配字符串
int find_str(string a,string p,int start_pos)
{
    int n = a.length()-p.length();
    if((start_pos>n)||start_pos<0)
        return -1;
    for(int i=start_pos;i<n;i++)
    {
        string s_str = a.substr(i,p.length());
        if(s_str == p)
        {
            cout<<"找到字符串"<<"\n";
            return i;
        }
    }
    return -1;
}
int main() {
    string a = "abbcbaabababcabcc";
    string b = "abc";
    int n = a.length()-b.length();
    cout<<find_str2(a,b,0);
}